/**
 * @param {string} colors
 * @param {number[][]} edges
 * @return {number}
 */
// 不太会图
 var largestPathValue = function(colors, edges) {
    const map = new Map(), count = new Map()
    for(let i = 0; i<colors.length; i++){
        map.set(i, colors[i])
        count.set(colors[i],0)
    }
    const eset = new Set()
    for(let [x,y] of edges){
        if(edges.some(item => item[1] == x && (item[0] > y || item[0] == x)))
            return -1
        eset.add(x).add(y)
    }
    for(let x of eset)
        count.set(map.get(x),count.get(map.get(x))+1)
    return Math.max(...count.values())
};